"use strict";
export default {
  // centerAdminIp: 'http://localhost:8080',
  //邮箱
  emailReg: /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/,
  //验证手机号
  phoneReg: /^1[3|4|5|7|8][0-9]{9}$/,
  //6到13位数字与字母组合
  pwdReg: /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,13}$/,
  //数字或字符串6-20位
  StrNumReg: /^[a-zA-Z0-9]{6,20}$/,
  //电话号码与手机号码同时验证
  mobileReg: /^0\d{2,3}-?\d{7,8}$/,
  telReg: /^(\(\d{3,4}\)|\d{3,4}-|\s)?\d{7,12}$/,
  // 截取地址栏信息
  getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
  },
  numToEn(month) { //数字转换成英文
    var m = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Spt", "Oct", "Nov", "Dec");
    var mm = m[month - 1];
    // //console.log(m[month-1]);
    return mm;
  },
  mathNum(L) {  // 生成随机多少位数 字母与数字的组合
    var s = "";
    var randomchar = function() {
      var n = Math.floor(Math.random() * 62);
      if (n < 10) return n; //1-10
      if (n < 36) return String.fromCharCode(n + 55); //A-Z
      return String.fromCharCode(n + 61); //a-z
    };
    while (s.length < L) s += randomchar();
    return s;
  },
  sizeof(str) { //判断字符串长度
    var total = 0,
      charCode,
      i,
      len;
    for (i = 0, len = str.length; i < len; i++) {
      charCode = str.charCodeAt(i);
      if (charCode <= 0x007f) {
        total += 1;
      } else if (charCode <= 0x07ff) {
        total += 2;
      } else if (charCode <= 0xffff) {
        total += 3;
      } else {
        total += 4;
      }
    }
    return total;
  },
  uniq(array){
    var temp = []; //一个新的临时数组
    for(var i = 0; i < array.length; i++){
        if(temp.indexOf(array[i]) == -1){
            temp.push(array[i]);
        }
    }
    return temp;
  },
  timeType(time) { //时间转换成时间戳
    var date = new Date(time.replace(/-/g, '/'));
    return date.getTime();
  },
  timeToNumber(timestamp) { //时间戳转换成时间
    let num = this.sizeof(timestamp.toString());
    let date = "";
    if(num == 10){
      date = new Date(timestamp * 1000);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
    } else {
      date = new Date(timestamp);
    }
    let Y = date.getFullYear() + '-';
    let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    let D = date.getDate() + ' ';
    let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours())  + ':';
    let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
    return Y + M + D + h + m + s;
  }
}
